package com.ihr360.job.core.repository.dao;

import com.ihr360.job.core.entity.JobExecution;
import com.ihr360.job.core.entity.StepExecution;

import java.util.Collection;
import java.util.List;

public interface StepExecutionDao {

    /**
     * Save the given StepExecution.
     * <p>
     * Preconditions: Id must be null.
     * <p>
     * Postconditions: Id will be set to a unique Long.
     *
     * @param stepExecution
     */
    void saveStepExecution(StepExecution stepExecution);

    /**
     * Save the given collection of StepExecution as a batch.
     * <p>
     * Preconditions: StepExecution Id must be null.
     * <p>
     * Postconditions: StepExecution Id will be set to a unique Long.
     *
     * @param stepExecutions
     */
    void saveStepExecutions(Collection<StepExecution> stepExecutions);

    /**
     * Update the given StepExecution
     * <p>
     * Preconditions: Id must not be null.
     *
     * @param stepExecution
     */
    void updateStepExecution(StepExecution stepExecution);

    /**
     * Retrieve a {@link StepExecution} from its id.
     *
     * @param jobExecution    the parent {@link JobExecution}
     * @param stepExecutionId the step execution id
     * @return a {@link StepExecution}
     */
    StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId);

    List<StepExecution> getStepExecutions(JobExecution jobExecution);

    /**
     * Retrieve all the {@link StepExecution} for the parent {@link JobExecution}.
     *
     * @param jobExecution the parent job execution
     */
    void addStepExecutions(JobExecution jobExecution);

}
